var preferencesOverlay = {
   init: function() {
      var prefWindow = document.getElementById('BrowserPreferences');
      this.onPaneLoad(prefWindow.lastSelected);

      eval("prefWindow.showPane ="+prefWindow.showPane.toString().replace(
      'this._outer._selectPane(this._pane);',
      '$& preferencesOverlay.onPaneLoad(this._pane.id);'
      ));
   },

   onPaneLoad: function (aPaneID) {
      switch (aPaneID) {
         case "paneTabs":
            this.addButton();
         break;
         case "panePrivacy":
            this.onPanePrivacyLoad();
         break;
         default:
      }
   },

/* ........ paneTabs .............. */

   addButton: function () {
      var radiogroup = document.getElementById('linkTargeting');
      if (radiogroup) {
         radiogroup.removeAttribute('onsyncfrompreference');
         var radio = document.createElement('radio');
         radio.setAttribute('label', current.label.toLowerCase());
         radio.setAttribute('accesskey', current.accesskey);
         radio.setAttribute('value', '1');
         radiogroup.appendChild(radio);
         radiogroup.value = document.getElementById("browser.link.open_external").value;
      }
   
      var item = document.getElementById('linksOpenInBox') ||
                 document.getElementById("paneTabs").childNodes[2];

      if (!item) // we are lost :)
         return;

      var separator = document.createElement('separator');
      item.parentNode.insertBefore(separator, item);

      var hbox = document.createElement('hbox');
      item.parentNode.insertBefore(hbox, separator);

      var button = document.createElement('button');
      button.setAttribute('id', 'btn_tabtreemix');
      button.setAttribute('label', tmpOptions);
      button.setAttribute('oncommand', 'preferencesOverlay.showTabmixOptions();');
      hbox.appendChild(button);
   },

   showTabmixOptions: function () {
      var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                           .getService(Components.interfaces.nsIWindowMediator);

      var anyWindow = windowMediator.getMostRecentWindow('navigator:browser');
      
      if (!anyWindow) {
         var tabmixopt = windowMediator.getMostRecentWindow("mozilla:tabmixopt");
         if (tabmixopt)
            tabmixopt.close();

         var stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"]
                  .getService(Components.interfaces.nsIStringBundleService)
                  .createBundle("chrome://tabtreemix/locale/tabmix.properties");
         var title = stringBundle.GetStringFromName("tabmixoption.error.title");
         var msg = stringBundle.GetStringFromName("tabmixoption.error.msg");

         var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
                                    .getService(Components.interfaces.nsIPromptService);
         promptService.alert(window, title, msg);
      }
      else
         anyWindow.TMP_openDialog(-1);
   },

/* ........ panePrivacy .............. */

   onPanePrivacyLoad: function ()
   {
      if(gPrivacyPane.clearPrivateDataNow) {// clearPrivateDataNow not exist in firefox 1.5
         eval("gPrivacyPane.clearPrivateDataNow ="+gPrivacyPane.clearPrivateDataNow.toString().replace(
         'glue.sanitize(window || null);',
         '$& TMP_Sanitizer.tryToSanitize();'
         ));
      }
   }

}
